import {req_delete, req_get, req_post, req_put} from "@/request/cssdrequest";
import {R} from "@/type/dto/R";
import {OfficeDto} from "@/type/dto/OfficeDto";
import {ExamVO} from "@/type/vo/ExamVO";
import {RP} from "@/type/dto/RP";
import {PublishExamInfo} from "@/type/dto/PublicNaireDto";

export async function api_getExamList(startDate: string,
                                      dtEnd: string,
                                      examName: string,
                                      examType: number,
                                      status:number,
                                      page: number,
                                      limit: number) {

    const data = await req_get('/exam', {
        startDate,
        dtEnd,
        examName,
        examType,
        status,
        page,
        limit
    });
    //转成我要的json
    console.log('data:', data);
    return JSON.parse(data) as R<RP<ExamVO>>;
}

export async function api_deleteExam(deleteId: string) {

    const data = await req_delete('/exam', {
        id:deleteId
    });
    //转成我要的json
    console.log('data:', data);
    return JSON.parse(data) as R<object>;
}


export async function api_getExamInfo(examId: string) {
    const data = await req_get('/exam/detail', {
        id: examId
    });
    //转成我要的json
    console.log('data:', data);
    return JSON.parse(data) as R<ExamVO>;
}

export async function api_createExam(examType: number,
                                     creatorCode: string,
                                     title: string) {

    const data = await req_post('/exam', {
        examType,
        creatorCode,
        title,
        examStatus: 0,
        totalScore: 0
    });
    //转成我要的json
    console.log('data:', data);
    return JSON.parse(data) as R<ExamVO>;
}

export async function api_updateExam(exam:ExamVO) {

    const data = await req_put('/exam', exam);
    //转成我要的json
    console.log('data:', data);
    return JSON.parse(data) as R<string>;
}
export async function api_publicExam(officeExam:PublishExamInfo) {

    const data = await req_put('/exam/publish', officeExam);
    //转成我要的json
    console.log('data:', data);
    return JSON.parse(data) as R<string>;
}
